//
// Created by Administrator on 2023/7/30.
//
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

class Solution {
public:
    vector<int> separateDigits(vector<int> &nums) {
        vector<int> ans;
        stack<int>q;
        for (auto x: nums) {
            while (x) {
                q.push(x % 10);
                x /= 10;
            }
            while (!q.empty()) {
                ans.push_back(q.top());
                q.pop();
            }
        }
        return ans;
    }
};
class Solution2 {
public:
    vector<int> separateDigits(vector<int>& nums) {
        // 直接从后向前分解每个数，这样得到得结果全部会翻转，最后再翻转回来就行了。
        size_t nums_size = nums.size();
        vector<int>  vec;
        for(size_t i = nums_size; i > 0; --i)
        {
            int tmp = nums[i - 1];
            while(tmp > 0)
            {
                vec.push_back(tmp%10);
                tmp = tmp / 10;
            }
        }
        reverse(vec.begin(), vec.end());
        return vec;
    }
};
int main() {
    Solution s;
    vector<int> nums{13, 25, 83, 77};
    auto ans = s.separateDigits(nums);
    for (auto &x: ans)cout << x << endl;
}